package co.fitstart.entity.taste;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.apache.commons.lang3.StringUtils;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import co.fitstart.entity.order.Order;
import co.fitstart.entity.reference.Gender;
import co.fitstart.entity.user.User;

/**
 * 一元尝鲜报名
 * @author haiyan_xiao
 *
 */
@Entity
@Table(name = "taste_sign_up")
@JsonIgnoreProperties(value={"hibernate_lazy_initializer","handler","fieldHandler"})
public class TasteSignUp {
    
    @Id
    @GeneratedValue
    private Long id;
    
    /** BMI问卷 */
    @ManyToOne(fetch = FetchType.LAZY, optional = true)
    private BMIQuestion bmiQuestion;
    
    /** 姓名 */
    private String name;
    
    /** 手机号 */
    private String mobile;
    
    /** 微信号 */
    private String wechat;
    
    private Float weight;
    
    private Gender  gender;
    
    private Integer height;
    
    private Integer age;
    
    /** 用户 */
    @ManyToOne(fetch = FetchType.LAZY, optional = true)
    private User user;
    
    /** 订单 */
    @ManyToOne(fetch = FetchType.LAZY, optional = true)
    private Order order;
    
    /** 报名时间 */
    private Date createTime;
    
    private String source;
    
    /** 是否添加客服微信 */
    @Column(name = "is_service_added")
    private boolean serviceAdded;
    
    public TasteSignUp() {
        
    }
    
    /**
     * 
     * @param bmiQuestion
     * @param user
     * @return
     */
    public TasteSignUp initilization(BMIQuestion bmiQuestion, User user, Order order) {
        this.bmiQuestion = bmiQuestion;
        if(StringUtils.isBlank(source)) {
            source = null;
        } else {
            source = source.trim();
        }
        if(bmiQuestion != null) {
            this.gender = bmiQuestion.getGender();
            this.height = bmiQuestion.getHeight();
            this.weight = bmiQuestion.getWeight();
            this.age = bmiQuestion.getAge();
            if(source == null) {
                source = bmiQuestion.getSource();
            }
        }
        this.user = user;
        this.order = order;
        this.mobile = user.getMobile();
        this.createTime = new Date();
        return this;
    }
    
    /**
     * 
     * @param tasteSignUp
     * @return
     */
    public TasteSignUp edit(TasteSignUp tasteSignUp, BMIQuestion bmiQuestion) {
        this.name = tasteSignUp.getName();
        if(bmiQuestion != null) {
            this.gender = bmiQuestion.getGender();
            this.height = bmiQuestion.getHeight();
            this.weight = bmiQuestion.getWeight();
            this.age = bmiQuestion.getAge();
        } else {
            this.gender = tasteSignUp.getGender();
            this.height = tasteSignUp.getHeight();
            this.weight = tasteSignUp.getWeight();
            this.age = tasteSignUp.getAge();
        }
        this.wechat = tasteSignUp.getWechat();
        return this;
    }
    
    /**
     * 
     * @return
     */
    public TasteSignUp addService() {
        this.serviceAdded = true;
        return this;
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the bmiQuestion
     */
    public BMIQuestion getBmiQuestion() {
        return bmiQuestion;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @return the mobile
     */
    public String getMobile() {
        return mobile;
    }

    /**
     * @return the wechat
     */
    public String getWechat() {
        return wechat;
    }

    /**
     * @return the weight
     */
    public Float getWeight() {
        return weight;
    }

    /**
     * @return the gender
     */
    public Gender getGender() {
        return gender;
    }

    /**
     * @return the height
     */
    public Integer getHeight() {
        return height;
    }

    /**
     * @return the age
     */
    public Integer getAge() {
        return age;
    }

    /**
     * @return the user
     */
    public User getUser() {
        return user;
    }

    /**
     * @return the order
     */
    public Order getOrder() {
        return order;
    }

    /**
     * @return the createTime
     */
    public Date getCreateTime() {
        return createTime;
    }

    /**
     * @return the source
     */
    public String getSource() {
        return source;
    }

    /**
     * @return the serviceAdded
     */
    public boolean isServiceAdded() {
        return serviceAdded;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param bmiQuestion the bmiQuestion to set
     */
    public void setBmiQuestion(BMIQuestion bmiQuestion) {
        this.bmiQuestion = bmiQuestion;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @param mobile the mobile to set
     */
    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    /**
     * @param wechat the wechat to set
     */
    public void setWechat(String wechat) {
        this.wechat = wechat;
    }

    /**
     * @param weight the weight to set
     */
    public void setWeight(Float weight) {
        this.weight = weight;
    }

    /**
     * @param gender the gender to set
     */
    public void setGender(Gender gender) {
        this.gender = gender;
    }

    /**
     * @param height the height to set
     */
    public void setHeight(Integer height) {
        this.height = height;
    }

    /**
     * @param age the age to set
     */
    public void setAge(Integer age) {
        this.age = age;
    }

    /**
     * @param user the user to set
     */
    public void setUser(User user) {
        this.user = user;
    }

    /**
     * @param order the order to set
     */
    public void setOrder(Order order) {
        this.order = order;
    }

    /**
     * @param createTime the createTime to set
     */
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    /**
     * @param source the source to set
     */
    public void setSource(String source) {
        this.source = source;
    }

    /**
     * @param serviceAdded the serviceAdded to set
     */
    public void setServiceAdded(boolean serviceAdded) {
        this.serviceAdded = serviceAdded;
    }
}
